package clientUtilGUI;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.FontFormatException;
import java.awt.GraphicsEnvironment;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.Vector;

import javax.swing.DefaultCellEditor;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.Timer;
import javax.swing.UIManager;
import javax.swing.border.EtchedBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;

import object.Contract;
import object.Diplomas;
import object.District;
import object.EmployeeType;
import object.Position;
import object.Province;
import object.Specialized;
import objectView.DepartmentCom;
import objectView.EmSalarySheet;
import objectView.EmTimeSheet;
import objectView.EmployeeDepCom;
import objectView.SBCompany;
import objectView.SCCompany;
import objectView.UserAuthorization;
import utility.DayMonthYear;
import utility.StringUtil;
import utility.TimeServer;
import xml.XMLProcess;
import clientMain.Login;
import clientMain.Main;
import clientView.User_ChangePass;
import database.ContractDelegate;
import database.DiplomasDelegate;
import database.DistrictDelegate;
import database.EmployeeTypeDelegate;
import database.Paging;
import database.PositionDelegate;
import database.ProvinceDelegate;
import database.SBDelegate;
import database.SCDelegate;
import database.SpecializedDelegate;
import database.UserDelegate;

public class UtilityGUI {
	
	private static String exitSave;
	public static String exitApp;
	public static String exitTab;
	public static String exitTabbedPane(String tab){
		return exitTab +" ''"+tab+"'' ?\n"+exitSave;
	}
	public static void setExit(int local){
		Vector<String> exit = XMLProcess.readExit(local);
		exitSave = exit.get(0);
		exitApp = exit.get(1)+"\n"+exitSave;
		exitTab = exit.get(2);
	}
	
	public static String btnOk;
	public static String btnFind;
	public static String btnCal;
	public static String btnCancel;
	public static String btnSave;
	public static String btnEdit;
	public static String btnSelectFile;
	public static String btnUpload;
	public static String btnDeleteFile;
	public static String btnLog;
	public static String btnConfig;
	public static String btnRememberPwd;
	public static String btnView;
	public static String btnPrintImg;
	public static String btnPrintExcel;
	public static void setButton(int local){
		Vector<String> btn = XMLProcess.readBtnLocale(local);
		btnOk = btn.get(0);
		btnSave = btn.get(1);
		btnEdit = btn.get(2);
		btnCancel = btn.get(3);
		btnFind = btn.get(4);
		btnCal = btn.get(5);
		btnSelectFile = btn.get(6);
		btnUpload = btn.get(7);
		btnDeleteFile = btn.get(8);
		btnLog = btn.get(9);
		btnConfig = btn.get(10);
		btnRememberPwd = btn.get(11);
		btnView = btn.get(12);
		btnPrintImg = btn.get(13);
		btnPrintExcel = btn.get(14);
	}
	
	public static String titleAlert;
	public static String titleLogin;
	public static String titleMain;
	public static void setTitle(int local){
		Vector<String> title = XMLProcess.readTitLocale(local);
		titleAlert = title.get(0);
		titleLogin = title.get(1);
		titleMain  = title.get(2);
	}
	
	public static String lblLogin;
	public static String lblAcc;
	public static String lblPwd;
	public static void setLbl(int local){
		Vector<String> lbl = XMLProcess.readLblLocale(local);
		lblAcc = lbl.get(0);
		lblLogin = lbl.get(1);
		lblPwd = lbl.get(2);
	}
	
	//	ToolTipText
	public static String moreInfo;
	public static String moreInfoTs;
	public static String changePwd;
	public static void setToolTip(int local){
		Vector<String> lbl = XMLProcess.readToolTipLocale(local);
		changePwd = lbl.get(0);
		moreInfo = lbl.get(1);
		moreInfoTs = lbl.get(2);
	}
	
	/*************** FUNTION **************/	
	//	JTabbedPane Menu
	public static String menuCom;
	public static String menuDep;
	public static String menuEm;
	public static String menuSSTS;
	public static String menuReport;
	public static String menuUtility;
	public static String menuSupport;
	public static String menuAuth;	
	public static void setMenu(int local){
		Vector<String> menu = XMLProcess.readMenuLocale(local);
		menuCom = menu.get(0);
		menuDep = menu.get(1);
		menuEm = menu.get(2);
		menuSSTS = menu.get(3);
		menuReport = menu.get(4);
		menuUtility = menu.get(5);
		menuSupport = menu.get(6);
		menuAuth = menu.get(7);
	}
	
	//	JTabbedPane SubMenu
	public static String subMenuComInfo;
	public static String subMenuComEdit;	
	
	public static String subMenuDepInfo;
	public static String subMenuDepList;
	
	public static String subMenuEmSearch;
	public static String subMenuEmAdd;
	public static String subMenuEmList;
	
	public static String subMenuTS;
	public static String subMenuSSCal;
	public static String subMenuSSList;
	public static String subMenuSalaryCoefficent;
	public static String subMenuSalaryBonus;
	public static String subMenuStatistic;
	
	public static String subMenuReport;
	
	public static String subMenuProvince;
	public static String subMenuEmT;
	public static String subMenuPosition;
	public static String subMenuContract;
	public static String subMenuDiplomas;
	public static String subMenuSpecialized;	
	
	public static String subMenuReg;
	public static String subMenuSupport;
	public static String subMenuLienHe;
	
	public static String subMenuUserCreate;
	public static String subMenuUserEdit;
	public static String subMenuAdministrator;
	
	public static void setSubMenu(int local){
		Vector<String> subMenuXML = XMLProcess.readSubMenuLocale(local);
		subMenuComInfo = subMenuXML.get(0);
		subMenuComEdit = subMenuXML.get(1);
		subMenuDepInfo = subMenuXML.get(2);
		subMenuDepList = subMenuXML.get(3);
		subMenuEmSearch = subMenuXML.get(4);
		subMenuEmAdd = subMenuXML.get(5);
		subMenuEmList = subMenuXML.get(6);
		subMenuTS = subMenuXML.get(7);
		subMenuSSCal = subMenuXML.get(8);
		subMenuSSList = subMenuXML.get(9);
		subMenuSalaryCoefficent = subMenuXML.get(10);		
		subMenuSalaryBonus = subMenuXML.get(11);
		subMenuStatistic = subMenuXML.get(12);
		subMenuReport = subMenuXML.get(13);
		subMenuProvince = subMenuXML.get(14);
		subMenuEmT = subMenuXML.get(15);
		subMenuPosition = subMenuXML.get(16);
		subMenuContract = subMenuXML.get(17);
		subMenuDiplomas = subMenuXML.get(18);
		subMenuSpecialized = subMenuXML.get(19);
		subMenuReg = subMenuXML.get(20);
		subMenuSupport = subMenuXML.get(21);
		subMenuLienHe = subMenuXML.get(22);
		subMenuUserCreate = subMenuXML.get(23);
		subMenuUserEdit = subMenuXML.get(24);
		subMenuAdministrator = subMenuXML.get(25);
	}
	
	//	JTabbedPane Tab
	public static String tabComView;
	public static String tabComEdit;		
	
	public static String tabDepAdd;
	public static String tabDepEdit;
	public static String tabDepInfo;
	public static String tabDepList;
	
	public static String tabEmSearch;	
	public static String tabEmAdd;
	public static String tabEmEdit;
	public static String tabEmInfo;
	public static String tabEmComList;
	public static String tabEmDepList;

	public static String tabTS;
	public static String tabSSCal;
	public static String tabSSList;
	public static String tabSC;
	public static String tabSB;
	public static String tabStatistic;
	
	public static String tabReport;
	
	public static String tabProvince;
	public static String tabEmT;	
	public static String tabPosition;
	public static String tabContract;
	public static String tabDiplomas;
	public static String tabSpecialized;
	
	public static String tabRegulation;
	public static String tabSupport;
	public static String tabLienHe;

	public static String tabUserCreate;
	public static String tabUserEdit;
	public static String tabAdministrator;
	public static void setTab(int local){
		Vector<String> tabXML = XMLProcess.readTabLocale(local);
		tabComView = tabXML.get(0);
		tabComEdit = tabXML.get(1);
		tabDepAdd = tabXML.get(2);
		tabDepEdit = tabXML.get(3);		
		tabDepInfo = tabXML.get(4);
		tabDepList = tabXML.get(5);
		tabEmSearch = tabXML.get(6);
		tabEmAdd = tabXML.get(7);
		tabEmEdit = tabXML.get(8);
		tabEmInfo = tabXML.get(9);
		tabEmComList = tabXML.get(10);
		tabEmDepList = tabXML.get(11);
		tabTS = tabXML.get(12);
		tabSSCal = tabXML.get(13);
		tabSSList = tabXML.get(14);
		tabSC = tabXML.get(15);
		tabSB = tabXML.get(16);
		tabStatistic = tabXML.get(17);
		tabReport = tabXML.get(18);
		tabProvince = tabXML.get(19);
		tabEmT = tabXML.get(20);
		tabPosition = tabXML.get(21);
		tabContract = tabXML.get(22);
		tabDiplomas = tabXML.get(23);
		tabSpecialized = tabXML.get(24);
		tabRegulation = tabXML.get(25);
		tabSupport = tabXML.get(26);
		tabLienHe = tabXML.get(27);
		tabUserCreate = tabXML.get(28);
		tabUserEdit = tabXML.get(29);
		tabAdministrator = tabXML.get(30);
	}
	
// 	Notice	
	public static String noticeSalary;
	public static String noticeForm;
	public static void setNotice(int local){
		Vector<String> notice = XMLProcess.readNotice(local);
		noticeForm = notice.get(0);
		noticeSalary = notice.get(1);
	}
	//	Valid Data Form	
	public static String successAction;
	public static String successUpload;
	public static void setSuccess(int local){
		Vector<String> success = XMLProcess.readSuccess(local);
		successAction = success.get(0);
		successUpload = success.get(1);
	}
	
	public static String errorLogServer;
	public static String errorLogin1;
	public static String errorLogin2;	
	public static String errorAuth;
	public static String errorAuthEng;	
	public static String errorAction;	
	public static String errorImg;
	public static String errorValidEmId;
	public static String errorValidEmIdEng;
	public static String errorExistsEmId;
	public static String errorExistsEmIdEng;
	public static String errorValidUserName;
	public static String errorExistsUserName;
	public static String errorValidRoleName;
	public static String errorExistsRoleName;
	public static String errorPickAuthorization;
	private static String validName;
	private static String validData;
	private static String validNumber;
	public static String errorValidName(String dataField, int max, int min){
		return "'"+ dataField +"' "+ validName +" ["+ min + "-" + max + "] !!";
	}	
	public static String errorValid(String dataField){
		return "'"+ dataField +"' "+ validData;
	}	
	public static String errorValidNumber(String dataField, int min, int max){
		String error = "'"+ dataField + "' "+validNumber;
		if(min == -1 && max == -1) return error+"!!";
		else if(min == -1) return error + " < "+ max + "!!";
		else if(max == -1) return error + " > "+ min + "!!";
		else return error + " ["+min+"-"+max+"] !!";
	}
	public static void setError(int local){
		Vector<String> error = XMLProcess.readError(local);
		errorLogServer = error.get(0);
		errorLogin1 = error.get(1);
		errorLogin2 = error.get(2);
		errorAuth = error.get(3);
		errorAuthEng = error.get(4);
		errorAction = error.get(5);
		errorImg = error.get(6);
		errorValidEmId = error.get(7);
		errorValidEmIdEng = error.get(8);
		errorExistsEmId = error.get(9);
		errorExistsEmIdEng = error.get(10);
		errorValidUserName = error.get(11);
		errorExistsUserName = error.get(12);
		errorValidRoleName = error.get(13);
		errorExistsRoleName = error.get(14);
		errorPickAuthorization = error.get(15);
		validName = error.get(16);
		validData = error.get(17);
		validNumber = error.get(18);		
	}
	
	public static Toolkit tk = Toolkit.getDefaultToolkit();
	public static Dimension screenSize = tk.getScreenSize();
	public static Rectangle maxBounds = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
	
	public static Cursor cursorBtn = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
	
	public static Font fontHeader1 = new Font("Times New Roman", Font.BOLD, 21);
	public static Color colorHeader1 = new Color(4, 69, 5);
	
	public static Font fontHeader2 = new Font("Times New Roman", Font.BOLD, 17);
	public static Color colorHeader2 = new Color(185, 7, 24);
	
	public static Font fontHeader3 = new Font("Times New Roman", Font.BOLD, 15);
	public static Font fontLblForm = new Font("Tahoma", Font.BOLD, 13);
	public static Color colorLblForm = new Color(38, 94, 159);
	
	public static Font fontNote = new Font("Tahoma", Font.ITALIC, 11);
	public static Color colorNote = Color.RED;
	
	public static Font fontFooter = new Font("Tahoma", Font.BOLD, 9);
	
	public static Font fontBtnForm = new Font("Tahoma", Font.BOLD, 13);
	public static Font fontComboBox = new Font("Tahoma", Font.BOLD, 11);
	public static Color colorBgCbb = Color.DARK_GRAY;
	
	public static Font getFontTblHeader() {
		InputStream is = UtilityGUI.class.getResourceAsStream("/fonts/verdanab.TTF");
		Font font = null;
		try {
			font = Font.createFont(Font.TRUETYPE_FONT, is).deriveFont(13f);
		} catch (FontFormatException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return font;
	}
	public static Font fontTblHeader = getFontTblHeader();
	public static Color colorBgTblHeader = new Color(102, 102, 240);
	public static Color colorFgTblHeader = new Color(241, 247, 211);
	public static Font fontTbl = new Font("Tahoma", Font.PLAIN, 12);
	public static Font fontTblBold = new Font("Tahoma", Font.BOLD, 12);
	public static Color colorTxtTbl = Color.BLACK;
	public static Color colorEvenBgTbl = new Color(255,243,240);
	public static Color colorOddBgTbl = new Color(237,255,255);
	
	public static Font fontTxtUpdate = new Font("Tahoma", Font.PLAIN, 13);
	public static Font fontTxtInsert = new Font("Tahoma", Font.PLAIN, 13);
	public static Color colorOldTxtUpdate = new Color(88, 88, 88);
	public static Color colorNewTxtUpdate = Color.BLACK;
	public static Color colorBgOldTxtUpdate = new Color(214, 219, 226);
	public static Color colorBgNewTxtUpdate = Color.WHITE;
	
	public static Color colorSA = new Color(130,0,255);
	public static Color colorMod = new Color(255,115,50);
	public static Color colorMember = new Color(38, 94, 159);
	
	public static Color txtFocusError = Color.YELLOW;
	public static Color txtBlurError = Color.WHITE;

	public static Icon iconNext = new ImageIcon("src/image/next.png"); 
	public static Icon iconBack = new ImageIcon("src/image/back.png");


	
	
		

	/**
	 * @author Tidus
	 * @category Set cac thuoc tinh cho primay frame 
	 * @param JFrame 
	 */
	public static void themes(){
		try {   		
            com.jtattoo.plaf.acryl.AcrylLookAndFeel.setTheme("Green", "INSERT YOUR LICENSE KEY HERE", "MI-TEAM");
            UIManager.setLookAndFeel("com.jtattoo.plaf.acryl.AcrylLookAndFeel");
	    } catch (Exception e) { 
	    	e.printStackTrace();
	    }
	}
	public static void propertyFrameMain(Main main){
	    main.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
	    main.setBounds(0, 0, maxBounds.width, maxBounds.height);
	    main.setTitle(titleMain);
	    Image icon = tk.getImage(main.getClass().getResource("/image/featured.gif"));
	    main.setIconImage(icon);
	    main.setFont(new Font("Tahoma", Font.PLAIN, 12));
	    main.getContentPane().setLayout(new BorderLayout());
	    main.getContentPane().add(UtilityGUI.initHeader(), BorderLayout.NORTH);
	    main.getContentPane().add(UtilityGUI.initFooter(), BorderLayout.SOUTH);
	}
	
	
	/**
	 * @author dvp
	 * @category Tao header cho phan mem
	 * @return Componet Header
	 */
	public static JPanel initHeader(){
        JPanel panelHeader = new JPanel();
        panelHeader.setBorder(new EtchedBorder(EtchedBorder.RAISED, null, null));
		GridBagLayout gbl_panelHeader = new GridBagLayout();
		gbl_panelHeader.columnWidths = new int[]{0, 0};
		gbl_panelHeader.rowHeights = new int[]{0};
		gbl_panelHeader.columnWeights = new double[]{1.0, 0.0};
		gbl_panelHeader.rowWeights = new double[]{1.0};
		panelHeader.setLayout(gbl_panelHeader);
        
		JTabbedPane tbnPane = new JTabbedPane();
        tbnPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
        GridBagConstraints gbc_tbnPane = new GridBagConstraints();
        gbc_tbnPane.fill = GridBagConstraints.BOTH;
        gbc_tbnPane.insets = new Insets(0, 2, 0, 2);
        gbc_tbnPane.gridx = 0;
        gbc_tbnPane.gridy = 0;
        panelHeader.add(tbnPane, gbc_tbnPane);
        
        boolean funCom = false;
        boolean funDep = false;
        boolean funEm = false;
        boolean funSSTS = false;
        boolean funUtil = false;
        boolean funPerm = false;
        boolean funExcel = false;
        for(int i=0; i< Login.listAuthorization.size(); i++){
        	String authorization = Login.listAuthorization.get(i).getModuleName();
        	if(authorization.equals("Company")){
        		funCom = true;
        	}
        	if(authorization.equals("Department")){
        		funDep = true;
        	}
        	if(authorization.equals("Employee")){
        		funEm = true;
        	}
        	if(authorization.equals("TimeSheet") || authorization.equals("SalarySheet") || 
        			authorization.equals("SalaryCoefficient") || authorization.equals("SalaryBonus") ||
        			authorization.equals("TotalSalaryMonth") || authorization.equals("TotalSalaryQuarter") ||
        			authorization.equals("TotalSalaryYear")){
        		funSSTS = true;
        	}
        	if(Login.listAuthorization.get(i).getPermName().equals("Excel")){
        		funExcel = true;
    		}        	
        	if(authorization.equals("Contract") || authorization.equals("Diplomas") || 
        			authorization.equals("District") || authorization.equals("EmployeeType") ||
        			authorization.equals("Position") || authorization.equals("Province") || 
        			authorization.equals("Specialized")){
        		funUtil = true;
        	}
        	if(authorization.equals("Level") || authorization.equals("Module") ||
        			authorization.equals("Permission") || authorization.equals("Role") ||
        			authorization.equals("User")){
        		funPerm = true;
        	}
        	
        	
        }
        if(funCom){
        	tbnPane.addTab(menuCom, new Tab_Company());
        }
        if(funDep){
        	tbnPane.addTab(menuDep, new Tab_Department());
        }
        if(funEm){
        	tbnPane.addTab(menuEm, new Tab_Employee());
        }
        if(funSSTS){
        	tbnPane.addTab(menuSSTS, new Tab_SSTS());
        }
        if(funExcel){
       	 	tbnPane.addTab(menuReport, new Tab_Excel());
        }
        if(funUtil){
        	tbnPane.addTab(menuUtility, new Tab_Utility());
        }
        
        tbnPane.addTab(menuSupport, new Tab_Help());
        
        if(funPerm){
        	tbnPane.addTab(menuAuth, new Tab_Auth());
        }
        
        
		
        JPanel panelUser = new JPanel();
        GridBagConstraints gbc_panelUser = new GridBagConstraints();
        gbc_panelUser.fill = GridBagConstraints.BOTH;
        gbc_panelUser.insets = new Insets(0, 0, 0, 5);
        gbc_panelUser.gridx = 1;
        gbc_panelUser.gridy = 0;
        panelHeader.add(panelUser, gbc_panelUser);
        GridBagLayout gbl_panelUser = new GridBagLayout();
        gbl_panelUser.columnWidths = new int[]{0, 0, 0, 0, 0};
        gbl_panelUser.rowHeights = new int[]{0, 0, 0};
        gbl_panelUser.columnWeights = new double[]{1.0, 0.0, 0.0, 0.0, 0.0};
        gbl_panelUser.rowWeights = new double[]{0.5, 0.0, 0.5};
        panelUser.setLayout(gbl_panelUser);
        
        JButton btnImage = new JButton("",new ImageIcon("src/image/avatar.gif"));
        GridBagConstraints gbc_btnImage = new GridBagConstraints();
        gbc_btnImage.fill = GridBagConstraints.BOTH;
        gbc_btnImage.gridheight = 3;
        gbc_btnImage.gridwidth = 2;
        gbc_btnImage.insets = new Insets(8, 5, 7, 5);
        gbc_btnImage.gridx = 0;
        gbc_btnImage.gridy = 0;
        panelUser.add(btnImage, gbc_btnImage);
        
        int lvl = Login.listAuthorization.get(0).getLvlValue();
        Color color = null;
        if(lvl == 1){
        	color = colorSA;
        }else if(lvl == 2 || lvl == 3){
        	color = colorMod;
        }else if(lvl == 4){
        	color = colorMember;
        }
        JLabel lblUser = new JLabel("Account :");
        lblUser.setFont(fontLblForm);
        GridBagConstraints gbc_lblUser = new GridBagConstraints();
        gbc_lblUser.anchor = GridBagConstraints.WEST;
        gbc_lblUser.fill = GridBagConstraints.VERTICAL;
        gbc_lblUser.insets = new Insets(10, 5, 2, 5);
        gbc_lblUser.gridx = 2;
        gbc_lblUser.gridy = 0;
        panelUser.add(lblUser, gbc_lblUser);
                
        JLabel lblUserName = new JLabel(Login.listAuthorization.get(0).getUserName());
        lblUserName.setFont(fontLblForm);
        lblUserName.setForeground(color);
        GridBagConstraints gbc_lblUserName = new GridBagConstraints();
        gbc_lblUserName.anchor = GridBagConstraints.WEST;
        gbc_lblUserName.fill = GridBagConstraints.VERTICAL;
        gbc_lblUserName.insets = new Insets(10, 2, 2, 5);
        gbc_lblUserName.gridx = 3;
        gbc_lblUserName.gridy = 0;
        panelUser.add(lblUserName, gbc_lblUserName);
        
        JLabel lblEmId = new JLabel("Mã NV :");
        lblEmId.setFont(fontLblForm);
        GridBagConstraints gbc_lblEmId = new GridBagConstraints();
        gbc_lblEmId.fill = GridBagConstraints.VERTICAL;
        gbc_lblEmId.anchor = GridBagConstraints.WEST;
        gbc_lblEmId.insets = new Insets(5, 5, 2, 5);
        gbc_lblEmId.gridx = 2;
        gbc_lblEmId.gridy = 1;
        panelUser.add(lblEmId, gbc_lblEmId);
        
        JLabel lblId = new JLabel(Login.listAuthorization.get(0).getUserInfo());
        lblId.setFont(fontLblForm);
        lblId.setForeground(color);
        GridBagConstraints gbc_lblId = new GridBagConstraints();
        gbc_lblId.fill = GridBagConstraints.VERTICAL;
        gbc_lblId.anchor = GridBagConstraints.WEST;
        gbc_lblId.insets = new Insets(5, 2, 2, 5);
        gbc_lblId.gridx = 3;
        gbc_lblId.gridy = 1;
        panelUser.add(lblId, gbc_lblId);
        
        JLabel lblRole = new JLabel(Login.listAuthorization.get(0).getRoleName());
        lblRole.setFont(fontLblForm);
        lblRole.setForeground(color);
        GridBagConstraints gbc_lblRole = new GridBagConstraints();
        gbc_lblRole.gridwidth = 2;
        gbc_lblRole.fill = GridBagConstraints.VERTICAL;
        gbc_lblRole.anchor = GridBagConstraints.WEST;
        gbc_lblRole.insets = new Insets(5, 5, 5, 5);
        gbc_lblRole.gridx = 2;
        gbc_lblRole.gridy = 2;
        panelUser.add(lblRole, gbc_lblRole);
        
        JButton btnPass = new JButton(new ImageIcon("src/image/change_password.png"));
        btnPass.setToolTipText(changePwd);
        btnPass.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				new User_ChangePass(Main.main).setVisible(true);
			}
		});
        GridBagConstraints gbc_btnPass = new GridBagConstraints();
        gbc_btnPass.fill = GridBagConstraints.NONE;
        gbc_btnPass.anchor = GridBagConstraints.CENTER;
        gbc_btnPass.insets = new Insets(5, 0, 5, 5);
        gbc_btnPass.gridx = 4;
        gbc_btnPass.gridy = 2;
        panelUser.add(btnPass, gbc_btnPass);
        
        return panelHeader;
	}
	
	
	/**
	 * @author dvp
	 * @category Tao footer cho phan mem
	 * @return Componet Footer
	 */
	public static JPanel initFooter() {
		JPanel panelFooter = new JPanel();
		GridBagLayout gbl_panelFooter = new GridBagLayout();
		gbl_panelFooter.columnWidths = new int[]{0, 0};
		gbl_panelFooter.rowHeights = new int[]{0};
		gbl_panelFooter.columnWeights = new double[]{0.0, 1.0};
		gbl_panelFooter.rowWeights = new double[]{Double.MIN_VALUE};
		panelFooter.setLayout(gbl_panelFooter);
		panelFooter.setBorder(new EtchedBorder(EtchedBorder.RAISED, null, null));
		
		final JLabel lblTime = new JLabel(Main.strDate+" "+Main.strTime);	
		Timer timer = new Timer(1000*60, new ActionListener() {			
			@Override
			public void actionPerformed(ActionEvent e) {
				Main.fullday = TimeServer.toDate(TimeServer.getTimeServer());
				Main.strDate = Main.sdfDate.format(Main.fullday);
				Main.strTime = Main.sdfTime.format(Main.fullday);
				lblTime.setText(Main.strDate+" "+Main.strTime);
			}
		});
		timer.start();
		lblTime.setFont(fontFooter);
		lblTime.setForeground(new Color(0,80,35));
	    GridBagConstraints gbc_lblTime = new GridBagConstraints();
		gbc_lblTime.anchor = GridBagConstraints.WEST;
		gbc_lblTime.insets = new Insets(3, 8, 2, 0);
		gbc_lblTime.gridx = 0;
		gbc_lblTime.gridy = 0;
		panelFooter.add(lblTime, gbc_lblTime);
		
		String year;
		int y = Main.fullday.getYear()+1900;
		if(y == 2011){
			year = "2011";
		}else{
			year = "2011 - "+ y;
		}
		JLabel lblFooter = new JLabel("©© Copyright "+year+" MI-TEAM ©©");		
		lblFooter.setFont(fontFooter);
	    lblFooter.setForeground(colorHeader2);
	    GridBagConstraints gbc_lblFooter = new GridBagConstraints();
		gbc_lblFooter.anchor = GridBagConstraints.EAST;
		gbc_lblFooter.insets = new Insets(3, 0, 2, 8);
		gbc_lblFooter.gridx = 1;
		gbc_lblFooter.gridy = 0;
		panelFooter.add(lblFooter, gbc_lblFooter);
		return panelFooter;
	}
	
	
	/**
	 * @author Tidus
	 * @param header: Tiêu đề lớn của Form
	 * @return Jpanel headerForm
	 */
	public static JPanel headerForm(String header){
		JPanel panelHeader = new JPanel();
		panelHeader = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 5));
		JLabel lblHeader = new JLabel(header);
		panelHeader.add(lblHeader);
		lblHeader.setFont(fontHeader1);
		lblHeader.setForeground(colorHeader1);
		return panelHeader;
	}
	
	
	/**
	 * @author Tidus
	 * @param title: Tiêu đề nhỏ của Form
	 * @return JPanel titleForm
	 */
	public static JPanel titleForm(String title){
		JPanel panelTitle = new JPanel();
		GridBagLayout gbl_paneTitle = new GridBagLayout();
		gbl_paneTitle.columnWidths = new int[]{0, 0, 0};
		gbl_paneTitle.rowHeights = new int[]{0};
		gbl_paneTitle.columnWeights = new double[]{0.05, 0.0, 1.0};
		gbl_paneTitle.rowWeights = new double[]{Double.MIN_VALUE};
		panelTitle.setLayout(gbl_paneTitle);
		
		JSeparator separator = new JSeparator();
		GridBagConstraints gbc_separator = new GridBagConstraints();
		gbc_separator.fill = GridBagConstraints.HORIZONTAL;
		gbc_separator.insets = new Insets(0, 10, 0, 5);
		gbc_separator.gridx = 0;
		gbc_separator.gridy = 0;
		panelTitle.add(separator, gbc_separator);
		
		JLabel lblTitle = new JLabel(title);
		lblTitle.setForeground(colorHeader2);
		lblTitle.setFont(fontHeader2);
		GridBagConstraints gbc_lblTitle = new GridBagConstraints();
		gbc_lblTitle.fill = GridBagConstraints.BOTH;
		gbc_lblTitle.insets = new Insets(0, 5, 0, 5);
		gbc_lblTitle.gridx = 1;
		gbc_lblTitle.gridy = 0;
		panelTitle.add(lblTitle, gbc_lblTitle);
		
		JSeparator separator_1 = new JSeparator();
		GridBagConstraints gbc_separator_1 = new GridBagConstraints();
		gbc_separator_1.insets = new Insets(0, 5, 0, 15);
		gbc_separator_1.fill = GridBagConstraints.HORIZONTAL;
		gbc_separator_1.gridx = 2;
		gbc_separator_1.gridy = 0;
		panelTitle.add(separator_1, gbc_separator_1);
		
		return panelTitle;
	}
	
	
	
	/**
	 * @author Tidus
	 * @return JComboBox
	 * @param String table: tên bảng.
	 * 		  VD: [Province], [District], [EmployeeType], [Department], 
	 * 			  [Specialized], [Position], [Diplomas], [Contract]
	 * @param int idProvince: dùng cho bảng District. Nếu hàm dùng cho bảng khác thì chuyền vào 0
	 */
	public static JComboBox getComboBox(String table, int idProvince , String name){
		JComboBox comboBox = new JComboBox();
		if(table == "Province"){
			Vector<Province> listProvinces;
			ProvinceDelegate provinceDelegate = new ProvinceDelegate();
			listProvinces = provinceDelegate.getListProvince(0, "ProvinceName", true);
			if(name ==""){
				comboBox.addItem("-- Chọn Tỉnh(Thành Phố) --");
			}else{
				comboBox.addItem(name);
			}
			comboBox.setFont(fontComboBox);
			for(int i=0;i<listProvinces.size();i++){
				String id = Integer.toString(listProvinces.get(i).getProvinceId());
				String value = listProvinces.get(i).getProvinceName();
				comboBox.addItem(new KeyValue(id, value));
			}
		}else if(table == "District"){
			Vector<District> listDistricts;
			DistrictDelegate districtDelegate = new DistrictDelegate();
			listDistricts = districtDelegate.getListDistrict(idProvince, "DistrictId", true);
			comboBox.addItem("-- Chọn Quận(huyện) --");
			comboBox.setFont(fontComboBox);
			for(int i = 1; i<listDistricts.size();i++){
				String id = Integer.toString(listDistricts.get(i).getDistrictId());
				String value = listDistricts.get(i).getDistrictName();
				comboBox.addItem(new KeyValue(id, value));
			}
		}else if(table == "Department"){
			Vector<DepartmentCom> listDep;
			listDep = Main.viewDep.getListDepInfo(Main.comId, 0, "Dep_Id", true);
			comboBox.addItem("-- Chọn Phòng Ban --");
			for(int i =0; i<listDep.size(); i++){
				String id = Integer.toString(listDep.get(i).getDepId());
				String value = listDep.get(i).getDepName();
				comboBox.addItem(new KeyValue(id, value));
			}
		}else if(table == "EmployeeType"){
			Vector<EmployeeType> listEmT;
			EmployeeTypeDelegate view = new EmployeeTypeDelegate();
			listEmT = view.getListEmT(0,"EmT_Id",true);
			comboBox.addItem("-- Chọn Nghiệp vụ --");
			for(int i =0; i<listEmT.size(); i++){
				String id = Integer.toString(listEmT.get(i).getEmTId());
				String value = listEmT.get(i).getEmTName();
				comboBox.addItem(new KeyValue(id, value));
			}
		}else if(table == "Contract"){
			Vector<Contract> listContracts;
			ContractDelegate view = new ContractDelegate();
			listContracts = view.getListContract(0,"Contract_Id",true);
			comboBox.addItem("-- Chọn Hợp Đồng --");
			for(int i =0; i<listContracts.size(); i++){
				String id = Integer.toString(listContracts.get(i).getContractId());
				String value = listContracts.get(i).getContractName();
				comboBox.addItem(new KeyValue(id, value));
			}
		}else if(table == "Position"){
			Vector<Position> listPositions;
			PositionDelegate view = new PositionDelegate();
			listPositions = view.getlistPosition(0,"Pos_Id",true);
			comboBox.addItem("-- Chọn Vị trí --");
			for(int i =0; i<listPositions.size(); i++){
				String id = Integer.toString(listPositions.get(i).getPosId());
				String value = listPositions.get(i).getPosName();
				comboBox.addItem(new KeyValue(id, value));
			}
		}else if(table == "Specialized"){
			Vector<Specialized> listSpecializeds;
			SpecializedDelegate view = new SpecializedDelegate();
			listSpecializeds = view.getListSpec(0,"Specialized_Id",true);
			comboBox.addItem("-- Chọn Chuyên Ngành --");
			for(int i =0; i<listSpecializeds.size(); i++){
				String id = Integer.toString(listSpecializeds.get(i).getSpecId());
				String value = listSpecializeds.get(i).getSpecName();
				comboBox.addItem(new KeyValue(id, value));
			}
		}else if(table == "Diplomas"){
			Vector<Diplomas> listDiplomas;
			DiplomasDelegate view = new DiplomasDelegate();
			listDiplomas = view.getListDiplomas(0,"Diplomas_Id",true);
			comboBox.addItem("-- Chọn Bằng Cấp --");
			for(int i =0; i<listDiplomas.size(); i++){
				String id = Integer.toString(listDiplomas.get(i).getDiplomasId());
				String value = listDiplomas.get(i).getDiplomasName();
				comboBox.addItem(new KeyValue(id, value));
			}
		}
		comboBox.setForeground(colorBgCbb);
		comboBox.setFont(fontComboBox);
		return comboBox;
	}
	
	
	/**
	 * @author Tidus
	 * @return comboBox paging
	 * @param String tableName: tên bảng || viewName : ten View
	 */
	public static JComboBox cbbPaging(String name){
		int totalPage = Paging.getTotalPage(name);
		JComboBox cbbPage = new JComboBox();
		for(int i=0; i<totalPage; i++){
			cbbPage.addItem(i+1);
		}
		cbbPage.setSelectedIndex(0);
		cbbPage.setFont(fontBtnForm);
		cbbPage.setPreferredSize(new Dimension(40, 20));
		return cbbPage;
	}
	
	
	/**
	 * @author Tidus
	 * @param depId: ma phong ban
	 * @return comboBox paging
	 */
	public static JComboBox cbbPaging(int depId){
		int totalPage = Paging.getTotalPage(depId);
		JComboBox cbbPage = new JComboBox();
		for(int i=0; i<totalPage; i++){
			cbbPage.addItem(i+1);
		}
		cbbPage.setSelectedIndex(0);
		cbbPage.setFont(fontBtnForm);
		cbbPage.setPreferredSize(new Dimension(40, 20));
		return cbbPage;
	}
	
	
	/**
	 * @author Tidus
	 * @param column: ten cot [Em_Id], [Em_FullName], [Pos_Name]
	 * @param String search
	 * @return comboBox paging
	 */
	public static JComboBox cbbPaging(String column, String search){
		int totalRec = Paging.getTotalRecord(column, search);
		int totalPage;
		if(totalRec % Main.record == 0){ 
		 	totalPage = totalRec/Main.record;
		}else{ 
			totalPage = totalRec/Main.record + 1;
		}
		if(totalPage > 0){
			JComboBox cbbPage = new JComboBox();
			for(int i=0; i<totalPage; i++){
				cbbPage.addItem(i+1);
			}
			cbbPage.setSelectedIndex(0);
			cbbPage.setFont(fontBtnForm);
			cbbPage.setPreferredSize(new Dimension(40, 20));
			return cbbPage;
		}else return null;
	}
	
	
	/**
	 * @author Tidus
	 * @param monthYear[mm/yyyy]
	 * @param depId int
	 * @return comboBox paging
	 */
	public static JComboBox cbbPaging(String monthYear, int depId){
		int totalPage = Paging.getTotalPage(monthYear, depId);
		JComboBox cbbPage = new JComboBox();
		for(int i=0; i<totalPage; i++){
			cbbPage.addItem(i+1);
		}
		cbbPage.setSelectedIndex(0);
		cbbPage.setFont(fontBtnForm);
		cbbPage.setPreferredSize(new Dimension(40, 20));
		return cbbPage;
	}
	
	
	public static JComboBox cbbQuaterofYear(){
		JComboBox cbb = new JComboBox();
		cbb.addItem("Quý I");
		cbb.addItem("Quý II");
		cbb.addItem("Quý III");
		cbb.addItem("Quý IV");
		cbb.setFont(fontBtnForm);
		cbb.setPreferredSize(new Dimension(80, 20));
		return cbb;
	}
	
	/**
	 * @author Tidus
	 * @param JList jList
	 * @param int total
	 * @category - divine 2 column 
	 * 			 - setFixedCellWidth
	 * 			 - setToolTipText
	 * 			 - setCursor
	 * 			 - setSelectionMode, setLayoutOrientation
	 * 			 - setFont, setForeground
	 */
	public static void styleJList(JList jList,int total){
		if(total > 5){
			if(total%2 == 0){
				jList.setVisibleRowCount(total/2);
			}else{
				jList.setVisibleRowCount(total/2+1);
			}
		}else{
			jList.setVisibleRowCount(total);
		}
		jList.setFixedCellWidth(250);
		jList.setToolTipText(moreInfo);
		jList.setCursor(cursorBtn);
		jList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		jList.setLayoutOrientation(JList.VERTICAL_WRAP);
		jList.setFont(fontLblForm);
		jList.setForeground(colorLblForm);
	}
	
	
	/**
	 * @author Tidus
	 * @param tbl
	 * @category - Highlight Row
	 * 			 - Set Header: font, bg, fg, ReorderingAllowed, setResizingAllowed
	 * 			 - setCursor, setRowHeight, setFont
	 * 			 - setAutoResizeMode
	 * 			 - setSelectionMode
	 */
	public static void styleJTable(JTable tbl){
		//	Add the stripe renderer.
	    StripedTableCellRenderer.installInTable(tbl, colorEvenBgTbl,
	    		colorTxtTbl, colorOddBgTbl, colorTxtTbl);
	    
	    //	Add MultiLine Header	    
	    MultiLineHeaderRenderer renderer = new MultiLineHeaderRenderer(colorBgTblHeader, colorFgTblHeader, fontTblHeader);
	    Enumeration e = tbl.getColumnModel().getColumns();
	    while (e.hasMoreElements()) {
	      ((TableColumn) e.nextElement()).setHeaderRenderer(renderer);
	    }
	    tbl.getTableHeader().setReorderingAllowed(false);
	    tbl.getTableHeader().setResizingAllowed(false);
		tbl.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
		tbl.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		tbl.setRowHeight(21);
	    tbl.setFont(fontTbl);
	    tbl.setCursor(cursorBtn);
	}
	
	
	/**
	 * @author Tidus
	 * @return JTable 
	 * @param tableName : tên objectView hoặc object
	 * @param page : muốn hiển thị page ?
	 * @param sort : sắp xếp theo cột ?
	 * @param flag : true[bé->lớn] , false[lớn->bé]
	 */
	public static JTable getTable(String tableName,int page, String sort,boolean flag){
		JTable tbl = null;
		DefaultTableModel model;
		Object[][] rowData = {};
		String[] columnNames = null;
		
		if(tableName == "DepartmentCom"){
			String[] col = {"STT", "Mã phòng ban", "Phòng ban", "Nhiệm Vụ", "Điện thoại", "Tổng số NV", btnEdit};
			columnNames = col;
			Vector<DepartmentCom> listDepComEms;
			listDepComEms = Main.viewDep.getListDepInfo(Main.comId, page, sort, flag);
			model = new DefaultTableModel(rowData, columnNames);
			for(int i= 0;i<listDepComEms.size();i++){
				DepartmentCom depCom = listDepComEms.get(i);
				Object[] dep = {i+1, depCom.getDepId(), depCom.getDepName(), depCom.getDepDescribe(),
								depCom.getDepPhone(), depCom.getDepTotalEm(), btnEdit};
				model.insertRow(i, dep);
			}
			final int count = col.length-1;
			tbl = new JTable(model){
				public boolean isCellEditable(int rowIndex, int colIndex) {
					if(colIndex == count){
						return true;
					}
					return false; //Disallow the editing of any cell
				}
			};
			tbl.setToolTipText(moreInfo);
			tbl.getColumnModel().getColumn(0).setPreferredWidth(40);
			tbl.getColumnModel().getColumn(1).setPreferredWidth(110);
			tbl.getColumnModel().getColumn(2).setPreferredWidth(200);
			tbl.getColumnModel().getColumn(3).setPreferredWidth(360);
			tbl.getColumnModel().getColumn(4).setPreferredWidth(100);
			tbl.getColumnModel().getColumn(5).setPreferredWidth(100);
			tbl.getColumnModel().getColumn(6).setPreferredWidth(80);
		
		}else if(tableName == "Contract"){
			String[] col = {"Mã Hợp Đồng", "Tên Hợp Đồng", "Mô Tả", btnEdit};
			columnNames = col;
			Vector<Contract> listContract;
			ContractDelegate view = new ContractDelegate();
			listContract = view.getListContract(page, sort, flag);
			model = new DefaultTableModel(rowData, columnNames);
			for(int i= 0;i<listContract.size();i++){
				Contract depCom = listContract.get(i);
				Object[] dep = {depCom.getContractId(), depCom.getContractName(),
						depCom.getContractDes(), btnEdit};
				model.insertRow(i, dep);
			}
			final int count = col.length-1;
			tbl = new JTable(model){
				public boolean isCellEditable(int rowIndex, int colIndex) {
					if(colIndex == count){
						return true;
					}
					return false; //Disallow the editing of any cell
				}
			};
			tbl.getColumnModel().getColumn(0).setPreferredWidth(120);
			tbl.getColumnModel().getColumn(1).setPreferredWidth(200);
			tbl.getColumnModel().getColumn(2).setPreferredWidth(350);
			tbl.getColumnModel().getColumn(3).setPreferredWidth(80);

		}else if(tableName == "EmployeeType"){
			String[] col = {"Mã Nghiệp Vụ", "Tên Nghiệp Vụ", "Mô Tả", btnEdit};
			columnNames = col;
			Vector<EmployeeType> listEmT;
			EmployeeTypeDelegate view = new EmployeeTypeDelegate();
			listEmT = view.getListEmT(page, sort, flag);
			model = new DefaultTableModel(rowData, columnNames);
			for(int i = 0; i<listEmT.size(); i++){
				EmployeeType emT = listEmT.get(i);			
				Object[] em = {emT.getEmTId(), emT.getEmTName(), emT.getEmTDescribe(), btnEdit};
				model.insertRow(i, em);
			}
			final int count = col.length-1;
			tbl = new JTable(model){
				public boolean isCellEditable(int rowIndex, int colIndex) {
					if(colIndex == count){
						return true;
					}
					return false; //Disallow the editing of any cell
				}
			};
			tbl.getColumnModel().getColumn(0).setPreferredWidth(150);
			tbl.getColumnModel().getColumn(1).setPreferredWidth(300);
			tbl.getColumnModel().getColumn(2).setPreferredWidth(450);
			
		}else if(tableName == "Province"){
			String[] col = {"Mã Tỉnh Thành", "Tên Tỉnh Thành", btnEdit};
			columnNames = col;
			Vector<Province> listProV;
			ProvinceDelegate view = new ProvinceDelegate();
			listProV = view.getListProvince(page, sort, flag);
			model = new DefaultTableModel(rowData, columnNames);
			for(int i= 0;i<listProV.size();i++){
			   Province depCom = listProV.get(i);
				Object[] dep = {depCom.getProvinceId(), depCom.getProvinceName(), btnEdit};
				model.insertRow(i, dep);
			}
			final int count = col.length-1;
			tbl = new JTable(model){
				public boolean isCellEditable(int rowIndex, int colIndex) {
					if(colIndex == count){
						return true;
					}
					return false; //Disallow the editing of any cell
				}
			};
			tbl.getColumnModel().getColumn(0).setPreferredWidth(140);
			tbl.getColumnModel().getColumn(1).setPreferredWidth(185);
			tbl.getColumnModel().getColumn(2).setPreferredWidth(80);
			
		}else if(tableName == "Position"){
			String[] col = {"Mã Chức Vụ", "Tên Chức Vụ","Mô Tả", btnEdit};
			columnNames = col;
			Vector<Position> listPos;
			PositionDelegate view = new PositionDelegate();
			listPos = view.getlistPosition(page, sort, flag);
			model = new DefaultTableModel(rowData, columnNames);
			for(int i= 0;i<listPos.size();i++){
			   Position depCom = listPos.get(i);
				Object[] dep = {depCom.getPosId(), depCom.getPosName(), depCom.getPosDes(), btnEdit};
				model.insertRow(i, dep);
			}
			final int count = col.length-1;
			tbl = new JTable(model){
				public boolean isCellEditable(int rowIndex, int colIndex) {
					if(colIndex == count){
						return true;
					}
					return false; //Disallow the editing of any cell
				}
			};
			tbl.getColumnModel().getColumn(0).setPreferredWidth(120);
			tbl.getColumnModel().getColumn(1).setPreferredWidth(180);
			tbl.getColumnModel().getColumn(2).setPreferredWidth(300);
			tbl.getColumnModel().getColumn(3).setPreferredWidth(80);
			
		}else if(tableName == "Diplomas"){
			String[] col = {"Mã Bằng Cấp", "Tên Bằng Cấp","Mô Tả", btnEdit};
			columnNames = col;
			Vector<Diplomas> listDip;
			DiplomasDelegate view = new DiplomasDelegate();
			listDip = view.getListDiplomas(page, sort, flag);
			model = new DefaultTableModel(rowData, columnNames);
			for(int i= 0;i<listDip.size();i++){
			   Diplomas depCom = listDip.get(i);
				Object[] dep = {depCom.getDiplomasId(), depCom.getDiplomasName(),depCom.getDiplomasDes(), btnEdit};
				model.insertRow(i, dep);
			}
			final int count = col.length-1;
			tbl = new JTable(model){
				public boolean isCellEditable(int rowIndex, int colIndex) {
					if(colIndex == count){
						return true;
					}
					return false; //Disallow the editing of any cell
				}
			};
			tbl.getColumnModel().getColumn(0).setPreferredWidth(150);
			tbl.getColumnModel().getColumn(1).setPreferredWidth(180);
			tbl.getColumnModel().getColumn(2).setPreferredWidth(180);
			tbl.getColumnModel().getColumn(3).setPreferredWidth(80);
		}
		else if(tableName == "Specialized"){
			String[] col = {"Mã Chuyên Nghành", "Tên Chuyên Nghành","Mô Tả", btnEdit};
			columnNames = col;
			Vector<Specialized> listSpe;
			SpecializedDelegate view = new SpecializedDelegate();
			listSpe = view.getListSpec(page, sort, flag);
			model = new DefaultTableModel(rowData, columnNames);
			for(int i= 0;i<listSpe.size();i++){
			   Specialized depCom = listSpe.get(i);
				Object[] dep = {depCom.getSpecId(), depCom.getSpecName(),depCom.getSpecDes(), btnEdit};
				model.insertRow(i, dep);
			}
			final int count = col.length-1;
			tbl = new JTable(model){
				public boolean isCellEditable(int rowIndex, int colIndex) {
					if(colIndex == count){
						return true;
					}
					return false; //Disallow the editing of any cell
				}
			};
			tbl.getColumnModel().getColumn(0).setPreferredWidth(150);
			tbl.getColumnModel().getColumn(1).setPreferredWidth(200);
			tbl.getColumnModel().getColumn(2).setPreferredWidth(400);
			tbl.getColumnModel().getColumn(3).setPreferredWidth(80);
		}else if(tableName.equals("SC")){
			String[] col = {"Mã HS", "Tên HS Lương", "HS Lương", 
					"Phòng Ban", "Chức Vụ", "Nghiệp Vụ", btnEdit};
			columnNames = col;
			Vector<SCCompany> listSC;
			SCDelegate view = new SCDelegate();
			listSC = view.getListSC(page, sort, flag);
			model = new DefaultTableModel(rowData, columnNames);
			for(int i= 0;i<listSC.size();i++){
			   SCCompany scc = listSC.get(i);
			   Object[] sc = {scc.getsCId(), scc.getsCName(), scc.getsCMoney(),
					   scc.getDepName(), scc.getPosName(), scc.getEmTName(), btnEdit};
			   model.insertRow(i, sc);
			}
			final int count = col.length-1;
			tbl = new JTable(model){
				public boolean isCellEditable(int rowIndex, int colIndex) {
					if(colIndex == count){
						return true;
					}
					return false; //Disallow the editing of any cell
				}
			};
			tbl.getColumnModel().getColumn(0).setPreferredWidth(70);
			tbl.getColumnModel().getColumn(1).setPreferredWidth(195);
			tbl.getColumnModel().getColumn(2).setPreferredWidth(140);
			tbl.getColumnModel().getColumn(3).setPreferredWidth(230);
			tbl.getColumnModel().getColumn(4).setPreferredWidth(140);
			tbl.getColumnModel().getColumn(5).setPreferredWidth(130);
			tbl.getColumnModel().getColumn(6).setPreferredWidth(80);
			
		}else if(tableName.equals("SB")){
			String[] col = {"Mã HS", "Tên HS Thưởng", "Tiền Thưởng", 
					"Mô tả", "Phòng Ban", btnEdit};
			columnNames = col;
			Vector<SBCompany> listSB;
			SBDelegate view = new SBDelegate();
			listSB = view.getListSB(page, sort, flag);
			model = new DefaultTableModel(rowData, columnNames);
			for(int i= 0;i<listSB.size();i++){
			   SBCompany sbc = listSB.get(i);
			   Object[] sb = {sbc.getsBId(), sbc.getsB_Name(), sbc.getsBMoney(),
					   sbc.getsBDescribe(), sbc.getDepName(), btnEdit};
			   model.insertRow(i, sb);
			}
			final int count = col.length-1;
			tbl = new JTable(model){
				public boolean isCellEditable(int rowIndex, int colIndex) {
					if(colIndex == count){
						return true;
					}
					return false; //Disallow the editing of any cell
				}
			};
			tbl.getColumnModel().getColumn(0).setPreferredWidth(70);
			tbl.getColumnModel().getColumn(1).setPreferredWidth(260);
			tbl.getColumnModel().getColumn(2).setPreferredWidth(155);
			tbl.getColumnModel().getColumn(3).setPreferredWidth(230);
			tbl.getColumnModel().getColumn(4).setPreferredWidth(190);
			tbl.getColumnModel().getColumn(5).setPreferredWidth(80);
		}
		//	DESIGN TABLE
		//	Add button
		if(tbl.getColumnName(tbl.getColumnCount()-1).equals(btnEdit)){
			tbl.getColumn(btnEdit).setCellRenderer(new ButtonRenderer());
			tbl.getColumn(btnEdit).setCellEditor(new ButtonEditor(new JCheckBox()));
		}
		styleJTable(tbl);
		return tbl;
	}

	/**
	 * /**
	 * @author Tidus
	 * @param page int
	 * @param check: [true]: xem tat ca nhan vien co DateEnd IS NULL || DateEnd > DateNow, 
	 * 				 [false] : xem toan bo danh sach NV tu trc den nay
	 * @param sort [Em_Id],[Em_LastName], [Dep_Name], [Diplomas_Name], [Specialized_Name]
	 * @param flag [true]: be->lon, [false]: lon->be
	 * @return list Employee In Company
	 * @return TblListEmCom
	 */
	
	public static JTable createTblListEmCom(boolean check ,int page, String sort,boolean flag){
		JTable tbl = null;
		DefaultTableModel model;
		Object[][] rowData = {};
		String[] columnNames = {"Mã NV", "Họ và Tên", "ĐTDĐ", 
				"Phòng Ban", "Chức Vụ", "Nghiệp Vụ", "Hợp Đồng",
				"Ngày Bắt Đầu", "Ngày Kết Thúc"};
		Vector<EmployeeDepCom> listEmployeeInCom;
		listEmployeeInCom = Main.viewEm.getListEmInCom(check, page, sort, flag);
		model = new DefaultTableModel(rowData, columnNames);
		for(int i = 0; i<listEmployeeInCom.size();i++){
			EmployeeDepCom emInfo = listEmployeeInCom.get(i);
			Object[] em = {emInfo.getEmId(), emInfo.getEmFullName(), 
					emInfo.getEmMobile(), emInfo.getDepName(), emInfo.getPosName(), 
					emInfo.getEmTName(), emInfo.getContractName(), 
					emInfo.getEmDateStart(), emInfo.getEmDateEnd()};
			model.insertRow(i, em);
		}
		tbl = new JTable(model){
			public boolean isCellEditable(int rowIndex, int colIndex) {
				return false; //Disallow the editing of any cell
			}
		};
		tbl.setToolTipText(moreInfo);
		tbl.getColumnModel().getColumn(0).setPreferredWidth(75);
		tbl.getColumnModel().getColumn(1).setPreferredWidth(180);
		tbl.getColumnModel().getColumn(2).setPreferredWidth(100);
		tbl.getColumnModel().getColumn(3).setPreferredWidth(200);
		tbl.getColumnModel().getColumn(4).setPreferredWidth(140);
		tbl.getColumnModel().getColumn(5).setPreferredWidth(130);
		tbl.getColumnModel().getColumn(6).setPreferredWidth(140);
		tbl.getColumnModel().getColumn(7).setPreferredWidth(115);
		tbl.getColumnModel().getColumn(8).setPreferredWidth(115);
		
		// DESIGN TABLE
		styleJTable(tbl);
		return tbl;
	}
	
	/**
	 * @author Tidus
	 * @param depId
	 * @param check: [true]: xem tat ca nhan vien co DateEnd IS NULL || DateEnd > DateNow, 
	 * 				[false] : xem toan bo danh sach NV tu trc den nay
	 * @param option: [true]: xem Em_FullName, Em_Id, Em_Position hien tai(dung trong timesheet)
	 * @param page
	 * @param sort: [Em_Id], [Em_LastName], [Pos_Name], [Em_DateStart]
	 * @param flag: [true]: be->lon, [false]: lon->be
	 * @return JTable ListEmTs
	 */
	public static JTable createTblListEmDep(int depId, boolean check, boolean option,
												int page, String sort, boolean flag){
		JTable tbl = new JTable(){
			public boolean isCellEditable(int rowIndex, int colIndex) {
				return false; //Disallow the editing of any cell
			}
		};
		
		DefaultTableModel model = new DefaultTableModel();
		Object[][] rowdata = {};
		Vector<EmployeeDepCom> listEm;
		if(option == true){
			listEm = Main.viewEm.getListEmInDep(depId, check, option, 1, sort, flag);
			String[] columnNames = {"Mã NV", "Họ và Tên", "Chức Vụ"};
			model.setDataVector(rowdata, columnNames);
			for(int i = 0; i<listEm.size(); i++){
				EmployeeDepCom emDep = listEm.get(i);			
				Object[] em = {emDep.getEmId(), emDep.getEmFullName(), emDep.getPosName()};
				model.insertRow(i, em);
			}
		}else{
			listEm = Main.viewEm.getListEmInDep(depId, check, option, page, sort, flag);
			String[] columnNames = {"Mã NV", "Họ và Tên", "ĐTDĐ", "Chức Vụ", "Nghiệp Vụ", 
										"Hợp Đồng",	"Ngày Bắt Đầu", "Ngày Kết Thúc"};
			model.setDataVector(rowdata, columnNames);
			for(int i = 0; i<listEm.size(); i++){
				EmployeeDepCom emDep = listEm.get(i);			
				Object[] em = {emDep.getEmId(), emDep.getEmFullName(), emDep.getEmMobile(),
						emDep.getPosName(), emDep.getEmTName(), emDep.getContractName(), 
						emDep.getEmDateStart(), emDep.getEmDateEnd()};
				model.insertRow(i, em);
			}
		}
		tbl.setModel(model);
		tbl.getColumnModel().getColumn(0).setPreferredWidth(75);
		tbl.getColumnModel().getColumn(1).setPreferredWidth(175);
		if(option == true){
			tbl.getColumnModel().getColumn(2).setPreferredWidth(140);
			styleJTable(tbl);
			tbl.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
			tbl.setFont(fontTblBold);
			tbl.setToolTipText(moreInfoTs);
		}else{
			tbl.getColumnModel().getColumn(2).setPreferredWidth(100);
			tbl.getColumnModel().getColumn(3).setPreferredWidth(140);
			tbl.getColumnModel().getColumn(4).setPreferredWidth(130);
			tbl.getColumnModel().getColumn(5).setPreferredWidth(140);
			tbl.getColumnModel().getColumn(6).setPreferredWidth(115);
			tbl.getColumnModel().getColumn(7).setPreferredWidth(115);
			styleJTable(tbl);
			tbl.setToolTipText(moreInfo);
		}
		return tbl;
	}
	

	/**
	 * @author Tidus
	 * @param  String emId, monthYear
	 * @return JTable EmTs_Modified
	 */
	public static JTable createTblEmTs(String emId, final String monthYear){
		JTable tbl = null;
		//	Khoi tao data cho bang
	    String[] columnNames = {"Ngày", "Ca Sáng", "Ca Chiều", "Ca tối", "Quyền"};
	    String[] rowNames = DayMonthYear.listDaysofMonth(monthYear);
	    final DefaultTableModel model = new DefaultTableModel(columnNames, rowNames.length);
	    
	    if(emId == null){
	    	for(int i=0; i <rowNames.length; i++){
		    	model.setValueAt(rowNames[i], i, 0);
		    	if(rowNames[i].contains(Main.strDate)){
		    		model.setValueAt("Thêm", i, 4);
		    	}else{
		    		model.setValueAt(btnEdit, i, 4);
		    	}
		    }
		    for(int i=0; i<rowNames.length; i++){
		    	for(int j = 1; j<columnNames.length-1; j++){
		    		model.setValueAt(false, i, j);
		    	}
		    }
		    tbl = new JTable(model){
				public boolean isCellEditable(int rowIndex, int colIndex) {
					return false;
				}
			};
	    }
	    else{
		    //	Load data vao bang:
	    	//	 * Ko có dữ liệu   	
		    //	 	- Neu la thang can lay data ngay truoc thang hien tai, ngay hien tai lon hon 5, 
		    //	    		hoac la cac thang # thi tra ve tbl = null
		    //	 	- Neu la thang can lay data ngay truoc thang hien tai, ngay hien tai nho hon 5, 
		    //    			thi tra ve tra ve tbl = ""		    
		    //	 	- Neu la thang hien tai chua co du lieu 
	    	//	    		thi tra ve tbl = ""
	    	//	 * Có dữ liệu    	
		    //	 	- Neu la thang hien tai tra ve nhung ngay có data 
		    //      		 va nhung ngay ko co data thi gan = false
		    Vector<EmTimeSheet> list;
		    list = Main.viewEm.getEmTimeSheet(monthYear, emId);
		    if(list.size() == 0 || list == null){
		    	Vector<String> listStr = StringUtil.subStr(monthYear, "/");
		    	int month = Integer.parseInt(listStr.get(0));
		    	int year = Integer.parseInt(listStr.get(1));
			    if(year == Main.fullday.getYear()+1900 && month == Main.fullday.getMonth()
			    				&& Main.fullday.getDate() >5){
			    	return tbl;
			    }else if(Main.strDate.contains(monthYear) 
			    		|| (year == Main.fullday.getYear()+1900 && month == Main.fullday.getMonth() 
			    				&& Main.fullday.getDate() <=5)){
				    for(int i=0; i<rowNames.length; i++){
				    	for(int j = 1; j<columnNames.length-1; j++){
				    		model.setValueAt(false, i, j);
				    	}
				    }
				    for(int i=0; i <rowNames.length; i++){
				    	model.setValueAt(rowNames[i], i, 0);
				    	if(rowNames[i].contains(Main.strDate) && model.getValueAt(i, 1).equals(false) 
				    			&& model.getValueAt(i, 2).equals(false) 
				    			&& model.getValueAt(i, 3).equals(false)){
				    		model.setValueAt("Thêm", i, 4);
				    	}else{
				    		model.setValueAt(btnEdit, i, 4);
				    	}
				    }
				    final int day = Main.fullday.getDate();
				    tbl = new JTable(model){
				    	public boolean isCellEditable(int rowIndex, int colIndex) {
							if(colIndex == 0){
								return false;
							}else if(rowIndex != day-1 && colIndex !=4){
								return false;
							}else if(rowIndex == day-1 && model.getValueAt(rowIndex, 4).equals(btnEdit) && colIndex !=4){
								return false;
							}
							return true;
						}
					};
			    }else{ 
			    	return tbl;
			    }
		    }else if(list.size() != 0){
		    	for(int i=0; i<rowNames.length; i++){
			    	for(int j = 1; j<columnNames.length-1; j++){
			    		model.setValueAt(false, i, j);
			    	}
			    }
			    for(int i=0; i<rowNames.length; i++){
			    	for(int j=0; j<list.size(); j++){
			    		if(rowNames[i].equals(list.get(j).getTsDate())){
				    		model.setValueAt(list.get(j).isTsMorning(), i, 1);			    		
				    		model.setValueAt(list.get(j).isTsAfternoon(), i, 2);			 
				    		model.setValueAt(list.get(j).isTsEvening(), i, 3);
				    	}
			    	}
			    }
			    for(int i=0; i <rowNames.length; i++){
			    	model.setValueAt(rowNames[i], i, 0);
			    	if(rowNames[i].contains(Main.strDate) && model.getValueAt(i, 1).equals(false) 
			    			&& model.getValueAt(i, 2).equals(false) 
			    			&& model.getValueAt(i, 3).equals(false)){
			    		model.setValueAt("Thêm", i, 4);
			    	}else{
			    		model.setValueAt(btnEdit, i, 4);
			    	}
			    }
			    final int day = Integer.parseInt(StringUtil.subStr(Main.strDate, "/").get(0));
			    tbl = new JTable(model){
					public boolean isCellEditable(int rowIndex, int colIndex) {
						if(colIndex == 0){
							return false;
						}else if(Main.strDate.contains(monthYear)){
							if(rowIndex != day-1 && colIndex !=4){
								return false;
							}else if(rowIndex == day-1 && model.getValueAt(rowIndex, 4).equals(btnEdit) && colIndex !=4){
								return false;
							}
						}else if(Main.strDate.contains(monthYear) == false){
							return false;
						}
						return true;
					}
				};
		    }
		}
		//	Tao button
		tbl.getColumn("Quyền").setCellRenderer(new ButtonRenderer());
		tbl.getColumn("Quyền").setCellEditor(new ButtonEditor(new JCheckBox()));
		
		//	Tao checkbox	        
	    CheckBoxRenderer checkBoxRenderer = new CheckBoxRenderer();
	    EachRowRenderer rowRenderer = new EachRowRenderer();
	    
	    JCheckBox checkBox = new JCheckBox();
	    checkBox.setHorizontalAlignment(JLabel.CENTER);
	    DefaultCellEditor checkBoxEditor = new DefaultCellEditor(checkBox);
	    
	    EachRowEditor rowEditor = new EachRowEditor(tbl);
	    
	    for(int i = 0; i<rowNames.length; i++){
	    	rowRenderer.add(i, checkBoxRenderer);
	    	rowEditor.setEditorAt(i, checkBoxEditor);
	    }
	    for(int j = 1; j<columnNames.length-1; j++){
	    	tbl.getColumnModel().getColumn(j).setCellRenderer(rowRenderer);
	    	tbl.getColumnModel().getColumn(j).setCellEditor(rowEditor);
	    }
	    
	    //	Design table
	    for(int i = 0; i<columnNames.length; i++){
	    	tbl.getColumnModel().getColumn(i).setPreferredWidth(90);
	    }
	    styleJTable(tbl);
	    tbl.setFont(fontTblBold);
	    tbl.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
		return tbl;
	}
	
	
	/**
	 * @author Tidus
	 * @param  Vector<EmTimeSheet> emTS, String monthYear
	 * @return JTable EmTs_View
	 */
	public static JTable getTblEmTs(Vector<EmTimeSheet> emTS, final String monthYear){
		JTable tbl = null;
		//	Khoi tao data cho bang
	    String[] columnNames = {"Ngày", "Ca Sáng", "Ca Chiều", "Ca tối"};
	    String[] rowNames = DayMonthYear.listDaysofMonth(monthYear);
	    final DefaultTableModel model = new DefaultTableModel(columnNames, rowNames.length);
	    for(int i=0; i<rowNames.length; i++){
	    	for(int j = 1; j<columnNames.length; j++){
	    		model.setValueAt(false, i, j);
	    	}
	    }
	    for(int i=0; i<rowNames.length; i++){
	    	for(int j=0; j<emTS.size(); j++){
	    		if(rowNames[i].equals(emTS.get(j).getTsDate())){
		    		model.setValueAt(emTS.get(j).isTsMorning(), i, 1);			    		
		    		model.setValueAt(emTS.get(j).isTsAfternoon(), i, 2);			 
		    		model.setValueAt(emTS.get(j).isTsEvening(), i, 3);
		    	}
	    	}
	    }
	    CheckBoxRenderer checkBoxRenderer = new CheckBoxRenderer();
	    EachRowRenderer rowRenderer = new EachRowRenderer();
	    
	    JCheckBox checkBox = new JCheckBox();
	    checkBox.setHorizontalAlignment(JLabel.CENTER);
	    DefaultCellEditor checkBoxEditor = new DefaultCellEditor(checkBox);
	    
	    EachRowEditor rowEditor = new EachRowEditor(tbl);
	    
	    for(int i = 0; i<rowNames.length; i++){
	    	model.setValueAt(rowNames[i], i, 0);
	    	rowRenderer.add(i, checkBoxRenderer);
	    	rowEditor.setEditorAt(i, checkBoxEditor);
	    }
	    
	    tbl = new JTable(model){
			public boolean isCellEditable(int rowIndex, int colIndex) {
				return false; //Disallow the editing of any cell
			}
		};
	    for(int j = 1; j<columnNames.length; j++){
	    	tbl.getColumnModel().getColumn(j).setCellRenderer(rowRenderer);
	    	tbl.getColumnModel().getColumn(j).setCellEditor(rowEditor);
	    }
	    
	    //	Design table
	    for(int i = 0; i<columnNames.length; i++){
	    	tbl.getColumnModel().getColumn(i).setPreferredWidth(86);
	    }
	    styleJTable(tbl);
	    tbl.setFont(fontTblBold);
	    tbl.setRowHeight(20);
		return tbl;
	}
	
	
	/**
	 * @author Tidus
	 * @param monthYear
	 * @param depId
	 * @param page
	 * @param sort
	 * @param flag
	 * @return JTable ListSS in Dep
	 */
	public static JTable getTblListSSinDep(String monthYear, int depId, int page, String sort, boolean flag){
		Object[][] rowData = {};
		String[] columnNames = {"Mã NV", "Họ và Tên", "TS Ca Sáng", "Lương Ca Sáng", 
				"TS Ca Đêm", "Lương Ca Đêm", "Thưởng", "Lương(%NVCT)", "Tổng Lương"};
		Vector<EmSalarySheet> list = Main.viewEm.getListEmSS(monthYear, depId, page, sort, flag);
		DefaultTableModel model = new DefaultTableModel(rowData, columnNames);
		for(int i= 0;i<list.size();i++){
			EmSalarySheet emSS = list.get(i);
			Object[] ss = {emSS.getEmId(), emSS.getEmFullName(), emSS.getTotalAM(),	emSS.getSalaryAM(), 
					emSS.getTotalPM(), emSS.getSalaryPM(), emSS.getSb(), emSS.getContractBenefit(),
					emSS.getTotalSalary()};
			model.insertRow(i, ss);
		}
		JTable tbl = new JTable(model){
			public boolean isCellEditable(int rowIndex, int colIndex) {
				return false; //Disallow the editing of any cell
			}
		};
		tbl.setToolTipText(moreInfo);
		tbl.getColumnModel().getColumn(0).setPreferredWidth(60);
		tbl.getColumnModel().getColumn(1).setPreferredWidth(160);
		tbl.getColumnModel().getColumn(2).setPreferredWidth(100);
		tbl.getColumnModel().getColumn(3).setPreferredWidth(130);
		tbl.getColumnModel().getColumn(4).setPreferredWidth(100);
		tbl.getColumnModel().getColumn(5).setPreferredWidth(130);
		tbl.getColumnModel().getColumn(6).setPreferredWidth(340);
		tbl.getColumnModel().getColumn(7).setPreferredWidth(130);
		tbl.getColumnModel().getColumn(8).setPreferredWidth(120);
		styleJTable(tbl);
		tbl.setToolTipText(moreInfo);
		return tbl;
	}
	
	/**
	 * @author Tidus
	 * @param  String userName
	 * @return JTable tblAuth
	 */	
	public static JTable getTblAuthorization(String userName){
		final Vector<UserAuthorization> listAuthLogin = Login.listAuthorization;
		Vector<UserAuthorization> listAuth = null;
		if(!userName.equals(Login.listAuthorization.get(0).getUserName())){
			UserDelegate userDelegate = new UserDelegate();
			listAuth = userDelegate.getListAuthorizations(userName);
		}
		String[] columnNames = {"No.", "Module","Module Describe", "Permision", "Tick"};
		Object[][] rowData = {};
		final DefaultTableModel model = new DefaultTableModel(rowData, columnNames) {
			Class[] columnTypes = new Class[] {
					Integer.class, String.class, String.class, String.class, Boolean.class
			};
			public Class getColumnClass(int columnIndex) {
				return columnTypes[columnIndex];
			}
		};
		for(int i =0; i<listAuthLogin.size(); i++){
			String moduleId = Integer.toString(listAuthLogin.get(i).getModuleId());
			String moduleValue = listAuthLogin.get(i).getModuleName();
			String permId = Integer.toString(listAuthLogin.get(i).getPermId());
			String permValue = listAuthLogin.get(i).getPermName();
			String moduleDes = listAuthLogin.get(i).getModuleDes();
			Object[] row = {i+1, new KeyValue(moduleId, moduleValue), moduleDes,
					new KeyValue(permId, permValue), false};
			model.insertRow(i, row);
		}
		if(listAuth != null){
			for(int i = 0; i<listAuthLogin.size(); i++){
				for(int j = 0; j< listAuth.size(); j++){
					if(listAuth.get(j).getModuleId() == listAuthLogin.get(i).getModuleId() && 
							listAuth.get(j).getPermId() == listAuthLogin.get(i).getPermId()){
						model.setValueAt(true, i, 4);
					}
				}
			}
		}
		JTable tbl = new JTable(model){
			public boolean isCellEditable(int rowIndex, int colIndex) {
				if(listAuthLogin.get(0).getLvlValue() == 3 &&
						listAuthLogin.get(rowIndex).getModuleName().equals("User")){
					return false;
				}else if(colIndex == 4){
					return true;
				}
				return false; //Disallow the editing of any cell
			}
		};
		tbl.getColumnModel().getColumn(0).setPreferredWidth(30);
	    tbl.getColumnModel().getColumn(1).setPreferredWidth(130);
	    tbl.getColumnModel().getColumn(2).setPreferredWidth(170);
	    tbl.getColumnModel().getColumn(3).setPreferredWidth(100);
	    tbl.getColumnModel().getColumn(4).setPreferredWidth(50);
	    
		styleJTable(tbl);
	    tbl.setRowHeight(20);
	    return tbl;
	}
	
	
	
	
	public static JTable createTblDistrict(int PrId,int page, String sort,boolean flag){
		JTable tbl = null;
		DefaultTableModel model;
		Object[][] rowData = {};
		String[] columnNames = {"Mã Quận Huyện", "Tên Quận Huyện", btnEdit};
		Vector<District> listDis;
		DistrictDelegate view = new DistrictDelegate();
		listDis = view.getListDistrict(PrId, sort, flag);
		model = new DefaultTableModel(rowData, columnNames);
		for(int i= 0;i<listDis.size();i++){
		   District depCom = listDis.get(i);
		   Object[] dep = {depCom.getDistrictId(), depCom.getDistrictName(), btnEdit};
		   model.insertRow(i, dep);
		}
		final int count = columnNames.length-1;
		tbl = new JTable(model){
			public boolean isCellEditable(int rowIndex, int colIndex) {
				if(colIndex == count){
					return true;
				}
				return false; //Disallow the editing of any cell
			}
		};

		tbl.getColumnModel().getColumn(2).setPreferredWidth(80);
		tbl.getColumn(btnEdit).setCellRenderer(new ButtonRenderer());
		tbl.getColumn(btnEdit).setCellEditor(new ButtonEditor(new JCheckBox()));
		
		tbl.getColumnModel().getColumn(0).setPreferredWidth(150);
		tbl.getColumnModel().getColumn(1).setPreferredWidth(280);
		tbl.getColumnModel().getColumn(2).setPreferredWidth(80);
		styleJTable(tbl);
		return tbl;
	}

}